package com.lsw.rabbitmq.listener;

import com.lsw.rabbitmq.entity.LoginMessage;
import com.lsw.rabbitmq.entity.RegistrationMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class QueueMessageListener {
    final Logger logger = LoggerFactory.getLogger(getClass());

    static final String QUEUE_MAIL = "q_mail";
    static final String QUEUE_SMS = "q_sms";
    static final String QUEUE_APP = "q_app";
    static final String QUEUE_ORDER = "ordertimeout_queue";

    //@RabbitListener(queues = QUEUE_MAIL)
    //public void onRegistrationMessageFromMailQueue(RegistrationMessage message) {
    //    logger.info("queue {} 收到注册消息: {}", QUEUE_MAIL, message);
    //}
    //
    //@RabbitListener(queues = QUEUE_SMS)
    //public void onRegistrationMessageFromSmsQueue(RegistrationMessage message) {
    //    logger.info("queue {} 收到注册消息: {}", QUEUE_SMS, message);
    //}
    //
    //@RabbitListener(queues = QUEUE_MAIL)
    //public void onLoginMessageFromMailQueue(LoginMessage message) {
    //    logger.info("queue {} 收到登录消息: {}", QUEUE_MAIL, message);
    //}
    //
    //@RabbitListener(queues = QUEUE_SMS)
    //public void onLoginMessageFromSmsQueue(LoginMessage message) {
    //    logger.info("queue {} 收到登录消息: {}", QUEUE_SMS, message);
    //}
    //
    //@RabbitListener(queues = QUEUE_APP)
    //public void onLoginMessageFromAppQueue(LoginMessage message) {
    //    logger.info("queue {} 收到登录消息: {}", QUEUE_APP, message);
    //}

    @RabbitListener(queues = QUEUE_ORDER)
    public void onCreateOrderMessageFromOrderQueue(Message message) {
        logger.info("queue {} 收到创建订单消息: {}", QUEUE_ORDER, message);
        // 判断订单有没有支付，如果没有支付则关闭订单，如果已经支付则将订单状态修改为已支付
    }
}